//
//  String+Extension.swift
//  05-来源处理
//
//  Created by Arvin on 15/11/22.
//  Copyright © 2015年 Arvin. All rights reserved.
//

import Foundation

extension String {
    
    // "<a href=\"http://app.weibo.com/t/feed/9ksdit\" rel=\"nofollow\">iPhone客户端</a>"
    func linkRef() -> (link: String?, clineName: String?) {
      
        // (.*?) 截取()中的内容
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        
        let regular = try?NSRegularExpression(pattern: pattern, options: [])
        
        let result = regular!.firstMatchInString(self, options: [], range: NSMakeRange(0, self.characters.count))
        
        let range2 = result?.rangeAtIndex(1)
        let range3 = result?.rangeAtIndex(2)
        
        var subStr2: String?
        var subStr3: String?
        if let r2 = range2,r3 = range3 {
            subStr2 = (self as NSString).substringWithRange(r2)
            subStr3 = (self as NSString).substringWithRange(r3)
        }
        return (subStr2, subStr3)
    }
    
}